package com.caijin.common.util;

import com.caijin.common.core.domain.dto.UserDTO;
import com.caijin.common.core.domain.entity.Student;
import com.caijin.common.core.domain.entity.Teacher;
import com.caijin.common.core.domain.vo.UserVO;

/**
 * 实体通用工具类
 *
 * @author Peas
 */
public class EntityUtil {

    /**
     * 用户模型转为学生模型
     *
     * @param userVO 前端传递的用户模型
     * @return
     */
    public static Student toStudent(UserVO userVO) {
        Student student = new Student();

        student.setSno(userVO.getId());
        student.setAvatar(userVO.getAvatar());
        student.setBirth(userVO.getBirth());
        student.setSex(userVO.getSex());
        student.setAdmissionTime(userVO.getAdmissionTime());
        student.setDepartmentId(userVO.getDepartmentId());
        student.setMajorId(userVO.getMajorId());
        student.setNickname(userVO.getNickname());
        student.setPhoneNumber(userVO.getPhoneNumber());
        student.setSname(userVO.getUsername());
        student.setPassword(userVO.getPassword());

        return student;
    }

    /**
     * 用户模型转为教师模型
     *
     * @param userVO 前端传递的用户模型
     * @return
     */
    public static Teacher toTeacher(UserVO userVO) {
        Teacher teacher = new Teacher();

        teacher.setTno(userVO.getId());
        teacher.setAvatar(userVO.getAvatar());
        teacher.setBirth(userVO.getBirth());
        teacher.setSex(userVO.getSex());
        teacher.setDepartmentId(userVO.getDepartmentId());
        teacher.setMajorId(userVO.getMajorId());
        teacher.setNickname(userVO.getNickname());
        teacher.setPhoneNumber(userVO.getPhoneNumber());
        teacher.setTname(userVO.getUsername());
        teacher.setPassword(userVO.getPassword());

        return teacher;
    }

    /**
     * 学生类型转换为DTO
     *
     * @param student
     * @return
     */
    public static UserDTO studentToUserDTO(Student student) {
        UserDTO userDTO = new UserDTO();
        userDTO.setId(student.getSno());
        userDTO.setName(student.getSname());
        userDTO.setNickName(student.getNickname());
        userDTO.setAvatar(student.getAvatar());
        userDTO.setType("1");
        return userDTO;
    }

    /**
     * 教师类型转换为DTO
     *
     * @param teacher
     * @return
     */
    public static UserDTO teacherToUserDTO(Teacher teacher) {
        UserDTO userDTO = new UserDTO();
        userDTO.setId(teacher.getTno());
        userDTO.setName(teacher.getTname());
        userDTO.setNickName(teacher.getNickname());
        userDTO.setAvatar(teacher.getAvatar());
        userDTO.setType("2");
        return userDTO;
    }

}
